//
//  MJDIYAutoHomeHeader.m
//  haoshuimian365
//
//  Created by admin  on 2018/9/5.
//  Copyright © 2018年 CYY or LZH. All rights reserved.
//

#import "MJDIYAutoHomeHeader.h"
#import "XLDotLoading.h"

@interface MJDIYAutoHomeHeader()
//@property (weak, nonatomic) UILabel *label;
@property (weak, nonatomic) UIImageView *imgV;
//@property (weak, nonatomic) UIImageView *animatingImgV;
//@property (weak, nonatomic) UIActivityIndicatorView *loading;
@end

@implementation MJDIYAutoHomeHeader
#pragma mark - 重写方法
#pragma mark 在这里做一些初始化配置（比如添加子控件）
- (void)prepare{
    [super prepare];
    // 设置控件的高度
    self.mj_h = viewPix(60)+iPhoneXMargin(20);
    self.backgroundColor = [UIColor clearColor] ;
    // 添加label
//    UILabel *label = [[UILabel alloc] init];
//    label.textColor = [UIColor orangeColor];
//    label.font = [UIFont systemFontOfSize:viewPix(12)];
//    label.textAlignment = NSTextAlignmentCenter;
//    [self addSubview:label];
//    self.label = label;
    
    UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"下拉刷新-箭头下"]];
    [self addSubview:imgV];
    self.imgV = imgV;
    
//    UIImageView * animatingImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"首页刷新-箭头下"]];
//    animatingImgV.backgroundColor = [UIColor redColor] ;
//    [self addSubview:animatingImgV];
//    self.animatingImgV = animatingImgV ;
    
    // loading
//    UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//    [self addSubview:loading];
//    self.loading = loading;
}

#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews{
    [super placeSubviews];
//    self.animatingImgV.frame = CGRectMake((Screen_W-viewPix(23))/2, viewPix(17/2), viewPix(23), viewPix(23));
//    self.label.frame = CGRectMake(0, viewPix(40), Screen_W, viewPix(20));
    self.imgV.center = CGPointMake(self.mj_w * 0.5, self.mj_h - viewPix(16));
//    self.loading.center = CGPointMake(30, self.mj_h * 0.5);
}

#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{
    [super scrollViewContentOffsetDidChange:change];
}

#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change{
    [super scrollViewContentSizeDidChange:change];
}

#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change{
    [super scrollViewPanStateDidChange:change];
}

#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state{
    MJRefreshCheckState;
    switch (state) {
        case MJRefreshStateIdle://闲置状态
            self.imgV.hidden = NO ;
            self.imgV.image = [UIImage imageNamed:@"下拉刷新-箭头下"] ;
            [XLDotLoading hideInView:self];
            break;
        case MJRefreshStatePulling://松开就可以进行刷新
            self.imgV.image = [UIImage imageNamed:@"下拉刷新-箭头上"] ;
            [XLDotLoading hideInView:self];
            break;
        case MJRefreshStateRefreshing://正在刷新中
            self.imgV.hidden = YES ;
            self.imgV.image = [UIImage imageNamed:@"下拉刷新-箭头上"] ;
            [XLDotLoading showInView:self];
            break;
        case MJRefreshStateWillRefresh://即将刷新
            
            break;
        case MJRefreshStateNoMoreData://数据加载完毕
            
            break;
        default:
            break;
    }
}

@end
